script_enemy_main{

let shotcount=0;
let bullets=15;

let shotspeed=1;

let spin=0;
let speed=0.4;

let shot1=0;
let bullet1=[];
let timer1=[];
let speed1=[];
let move1=[];

let bossangle=0;
let oldx=0;

let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let frame=0;
let time=0;
let move=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshotb5=("script\SoundEffects\shotb5.wav");
let SEmagicb2=("script\SoundEffects\magicb2.wav");

let GRboss=("\script\Images\CharacterSprites\Witches.png");

@Initialize{
	LoadGraphic("\script\Images\CharacterSprites\Witches.png");

	LoadSE("script\SoundEffects\shotb5.wav");
	LoadSE("script\SoundEffects\magicb2.wav");
	
	SetColor(170,0,30);
	Concentration01(90);
	SetColor(255,255,255);
	SetLife(10000);
	MagicCircle(false);
	SetInvincibility(120);
}
	
@MainLoop{

SetCollisionB(GetX,GetY,16);

if(GetX>oldx){ bossangle=180; }
else{ bossangle=0; }

SetMovePosition01(cx+200*cos(spin+180),cy+200*sin(spin+180),speed*3);
oldx=GetX;
spin+=speed;
speed+=0.0005;


if(frame==120){
	SetColor(170,0,30);
	Concentration01(90);
	SetColor(255,255,255);
}

if(frame==-30 && time>90){
let angle=GetAngleToPlayer;
	loop(10){
	CreateShot01(GetX,GetY,1*shotspeed,angle,25,10);
	CreateShot01(GetX,GetY,0.85*shotspeed,angle,37,10);
	CreateShot01(GetX,GetY,0.76*shotspeed,angle,49,10);
	CreateShot01(GetX,GetY,0.69*shotspeed,angle,61,10);
	angle+=360/10;
	}
shotspeed+=0.15;
PlaySE(SEshotb5);
}

if(frame>=180 && frame<185){
let angle=rand(0,360);
	loop(bullets){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,3);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	ObjShot_SetGraphic(shot1,11);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	speed1=speed1~[shot1];
	speed1[length(bullet1)-1]=rand(0.2,3);
	move1=move1~[shot1];
	move1[length(bullet1)-1]=0;
	angle+=360/bullets;
	}
}
if(frame==185){ PlaySE(SEmagicb2); frame=-180; bullets+=2; }

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); speed1=erase(speed1,i); move1=erase(move1,i);
	i--;
	}
	else{
	Obj_SetSpeed(bullet1[i],move1[i]);
	if(timer1[i]==180){ Obj_Delete(bullet1[i]); }
	move1[i]=speed1[i]*cos(timer1[i]);
	timer1[i]=timer1[i]+0.25;
	}
i++;
}



time++; frame++;
if(GetCommonData("UseSpell1")!=0){ usespell=GetCommonData("UseSpell1"); SetCommonData("UseSpell1",0); }
if(usespell>0){ usespell-=1; } if(usespell<0){ usespell+=1; }

SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicRect(0,outfit,128,outfit+128);
	if(usespell>=1){ SetGraphicRect(256,outfit,384,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5){ SetGraphicAngle(bossangle,0,0); }
		if(GetSpeedX>=0.5){ SetGraphicAngle(bossangle,0,0); }
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,"Youko");
}

}